# 系统自带库
import os

# 第三方库
from tornado.web import Application

# 自己写的
from app.ui.nav import NavModule
from app.ui.menu import MenuModule
from app.views.cookie_v import CookieHandler
from app.views.index_v import IndexHandler
from app.views.order_v import OrderHandler
from app.views.search_v import SearchHandler
from app.views.download import DownloadHandler, AsyncDownloadHandler
from app.views.message import MessageHandler,RobbitHandler

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

settings = {
    'debug': True,
    'template_path': os.path.join(BASE_DIR, 'templates'),
    # 服务器存放资源路径
    'static_path': os.path.join(BASE_DIR, 'static'),
    'static_url_prefix': '/s/',
    'ui_modules': {
        'Nav': NavModule,
        'Menu': MenuModule
    }
}

def make_app(host='licalhost'):
    return Application(handlers=[
        ('/', IndexHandler),
        ('/search', SearchHandler),
        ('/cookie',CookieHandler),
        ('/download', DownloadHandler),
        ('/download2',AsyncDownloadHandler),
        ('/robbit', RobbitHandler),
        ('/message',MessageHandler),
        # 1.
        # (r'/order/(\d+)/(\d+)',OrderHandler)

        # 2.正则写法 分组名称
        (r'/order/(?P<action_code>\d+)/(?P<order_id>\d+)', OrderHandler)
    ], default_host=host, **settings)